/*
 * Copyright (C) 2011 Wglxy.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.apis;

import com.database.DatabaseManager;

import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.TableLayout;
import android.widget.TextView;

/**
 * This is the activity for feature 3 in the dashboard application. It displays
 * some text and provides a way to get back to the home activity.
 * 
 */

public class F3Activity extends DashboardActivity {

	/**
	 * onCreate
	 * 
	 * Called when the activity is first created. This is where you should do
	 * all of your normal static set up: create views, bind data to lists, etc.
	 * This method also provides you with a Bundle containing the activity's
	 * previously frozen state, if there was one.
	 * 
	 * Always followed by onStart().
	 * 
	 * @param savedInstanceState
	 *            Bundle
	 */

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_f3);

		setTitleFromActivityLabel(R.id.title_text);
		DatabaseManager man = new DatabaseManager(this);
		DatabaseManager m1 = man.open();
		 m1.createMatchTableWithValues("Air India", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Churchill Brothers", "0", "0", "0","0", "0","0");
		 m1.createMatchTableWithValues("Dempo", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("East Bengal", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("HAL FC", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Indian Arrows", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("JCT", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Mohun Bagan", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Mumbai FC", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("ONGC", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Pune FC", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Salgaocar SC", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("United SC", "0", "0", "0","0", "0", "0");
		 m1.createMatchTableWithValues("Viva Kerala", "0", "0", "0","0", "0", "0");
		
		Cursor allCursor = m1.getAllTeamsCursor();
		 Log.d("JSON","here 74");
	setValues(allCursor);
	m1.close();
	

	}
	
	private void setValues(Cursor cursor)
	{
		
		cursor.moveToFirst();
		int a =R.id.team2;
		
		for(int i=0;i<cursor.getCount()-1;i++)
		{
			 
			TextView t1 = (TextView)findViewById(a);a++;t1.setText(cursor.getString(0));Log.d("JSON",cursor.getString(0));
			t1 = (TextView)findViewById(a);a++;t1.setText(cursor.getString(1));
			t1 = (TextView) findViewById(a);a++;t1.setText(cursor.getString(2));
			t1 = (TextView) findViewById(a);a++;t1.setText(cursor.getString(4));
			t1 = (TextView) findViewById(a);a++;t1.setText(cursor.getString(3));
			
			cursor.moveToNext();
		}
		TextView t1 = (TextView) findViewById(R.id.team15);t1.setText(cursor.getString(0));
		t1 = (TextView) findViewById(R.id.pts15);t1.setText(cursor.getString(1));
		t1 = (TextView) findViewById(R.id.won15);t1.setText(cursor.getString(2));
		t1 = (TextView) findViewById(R.id.drawn15);t1.setText(cursor.getString(3));
		t1 = (TextView) findViewById(R.id.lost15);t1.setText(cursor.getString(4));
	}

} // end class

// <TableRow>
// <TextView android:id="@+id/team1" android:layout_column="1"
// android:padding="3dip"></TextView>
// <TextView android:id="@+id/pts1" android:text="Pts" android:gravity="right"
// android:padding="3dip" />
// <TextView android:id="@+id/won1" android:text="Pts" android:gravity="right"
// android:padding="3dip" />
// <TextView android:id="@+id/lost1" android:text="Pts" android:gravity="right"
// android:padding="3dip" />
// <TextView android:id="@+id/drawn1" android:text="Pts" android:gravity="right"
// android:padding="3dip" />
// </TableRow>
// m1.createMatchTableWithValues("Air India", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Churchill Brothers", "0", "0", "0","0", "0",
// "0");
// m1.createMatchTableWithValues("Dempo", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("East Bengal", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("HAL FC", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Indian Arrows", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("JCT", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Mohun Bagan", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Mumbai FC", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("ONGC", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Pune FC", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Salgaocar SC", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("United SC", "0", "0", "0","0", "0", "0");
// m1.createMatchTableWithValues("Viva Kerala", "0", "0", "0","0", "0", "0");
//
